package Test;

import Service.PetService;
import entity.Pet;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.junit.Test;

public class AopTest {

    @Test
    public void testAop() {
        // 通过 ClassPathXmlApplicationContext 实例化 Spring 的上下文
        ApplicationContext context = 
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Pet pet = (Pet) context.getBean("pet");
        // 直接获取 service 对象，Spring 容器会帮我们组装对象，不需要获取 petDao 自行组装
        PetService petService = (PetService) context.getBean("petService");
        // 调用所有业务方法用于比较
        petService.save(pet);
        petService.modify(pet);
        petService.del(1);
    }
}